package com.sit.estatemanagementserver.controller;

import com.sit.estatemanagementserver.enity.Response;
import com.sit.estatemanagementserver.enity.VisitInfo;
import com.sit.estatemanagementserver.service.VisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
public class VisitorController {
    @Autowired
    private VisitorService visitorService;

    // --- VisitInfo Endpoints ---
    @PostMapping("/visit-infos/add")
    public Response<?> addVisitInfo(@RequestBody VisitInfo visitInfo) {
        if (visitorService.addVisitInfo(visitInfo)) {
            return Response.success();
        } else {
            return Response.error("新增访客信息失败");
        }
    }

    @GetMapping("/visit-infos/room/{roomNumber}")
    public Response<List<VisitInfo>> getVisitInfoByRoomNumber(@PathVariable String roomNumber) {
        List<VisitInfo> visitInfos = visitorService.getVisitInfoByRoomNumber(roomNumber);
        return Response.success(visitInfos);
    }
}